import { showUserInfo,showIdentity,showPort,showPower,showView,showRelation } from "../../api/showUser"
import { Message } from "element-ui"
const state = {
    userInfo: [],
    Identity: [],
    port:[],
    power:[],
    view:[],
    relation:[],
    total:0
}

const mutations = {
    showUserInfo(state, payload) {
        //展示用户数据
        state.userInfo = payload
    },
    showIdentity(state, payload) {
        //展示用户身份
        state.Identity = payload
    },
    showPort(state, payload) {
       //api接口权限
        state.port = payload
    },
    showPower(state, payload) {
         //展示身份和api权限关系
        state.power = payload
    },
    showView(state, payload) {
        //展示身份和api权限关系
       state.view = payload
   },
   showRelation(state, payload) {
    //展示身份和api权限关系
   state.relation = payload
},
}

const actions = {
    async getuser({commit}) {
        //获取用户数据
        const { data: res } = await showUserInfo()
        console.log(res)
        if (res.code !== 1) {
            Message.error(res.msg)
        }
        Message.success(res.msg)
        commit('showUserInfo', res.data)
    },
    async getIdentity({commit}) {
        //获取用户身份
        const { data: res } = await showIdentity()
        console.log(res)
        if (res.code !== 1) {
            Message.error(res.msg)
        }
        commit('showIdentity', res.data)
    },
    async getPort({commit}) {
        //获取api接口权限
        const { data: res } = await showPort()
        console.log(res)
        if (res.code !== 1) {
            Message.error(res.msg)
        }
        commit('showPort', res.data)
    },
    async getPower({commit}) {
        //身份和api接口关系
        const { data: res } = await showPower()
        console.log(res)
        if (res.code !== 1) {
            Message.error(res.msg)
        }
        commit('showPower', res.data)
    },
    async getView({commit}) {
        //获取视图接口权限
        const { data: res } = await showView()
        console.log(res)
        if (res.code !== 1) {
            Message.error(res.msg)
        }
        commit('showView', res.data)
    },
    async getrelation({commit}) {
        //展示身份和视图权限关系
        const { data: res } = await showRelation()
        console.log(res)
        if (res.code !== 1) {
            Message.error(res.msg)
        }
        commit('showRelation', res.data)
    },

}

export default {
    // 命令空间，为了在多人开发的时候防止命名冲突的一个手段
    // 因为最终需要在store.index 里面--引入各个模块,
    //为了防止命名冲突，如果加上这么一个字段之后,在不同的页面中
    //引入getters,actions，mutations时候，需要加上所属的模块名
    namespaced: true,
    state,
    mutations,
    actions
}